package org.jjche.serialize.transformer;

import lombok.RequiredArgsConstructor;
import org.jjche.common.api.CommonApi;
import org.jjche.common.dto.DictParam;
import org.jjche.common.transformer.IDictTransformer;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * 数据字典转换器
 * 该类需要业务自己实现，注意类名必须为DictTransformer，并使用@Component加入容器
 *
 * @author R
 */
@Component
@RequiredArgsConstructor
public class DictTransformer implements IDictTransformer<String> {
    private final CommonApi commonApi;

    @Override
    public String transform(@NonNull String dictCode, String group) {
        DictParam dictParam = commonApi.getDictByNameValue(group, dictCode);
        if (dictParam != null) {
            return dictParam.getLabel();
        }
        return null;
    }
}
